@extends('layouts.default')

@section('title', '')

@push('scripts')
<script src="{{ asset('lib/xm-select-v1.2.4/xm-select.js')}}"></script>
<script>
    layui.config({
        base: '/lib/Pear-Admin-Layui-next/component/pear/module/'
    }).extend({
        tableMerge: 'tableMerge'
    });
    layui.use(['layer','form','table','laytpl','laydate','element','laypage','upload','tableMerge'], function(){
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var laytpl = layui.laytpl;
        var laydate = layui.laydate;
        var element = layui.element;
        var laypage = layui.laypage;
        var upload = layui.upload;
        var tableMerge = layui.tableMerge;
        var xmDemo;
        var xmDemo2;
        var xmDemo3; //调取资料时间
        var xmDemo4; //岗位级别
        var xmDemo5; //参与老师
        var id = "{{request()->get('id',0)}}";
        var ct_id = "{{request()->get('ct_id',0)}}";
        var scale_id = "{{request()->get('scale_id',0)}}";
        var user_id = "{{request()->get('user_id',0)}}"; //老师账号

        laydate.render({
            elem: '#check_start'
        });
        laydate.render({
            elem: '#check_end'
        });
        laydate.render({
            elem: '#submit_start'
        });
        laydate.render({
            elem: '#submit_end'
        });

        element.on('tab(docDemoTabBrief)', function(){
            let lay_id =  this.getAttribute('lay-id');
            if(lay_id == 1){
                //最终认定
                $('.khxzcc-div').hide();
                _getFinalScores({'id':id,scale_id:scale_id,user_id:user_id,ct_id:ct_id});
            }else{
                //考核小组
                $('.khxzcc-div').show();
                let p_user_id = $('#kpxzcc').find('.kpxzcc-this').attr('user-id'); 
                _getCheckScores({'id':id,scale_id:scale_id,user_id:user_id,ct_id:ct_id,p_user_id:p_user_id});
            }
        });

        renderSelect(function(){
            //编辑
            if(id != 0){
                getTeacherBaseInfo2({'id':id,user_id:user_id,ct_id:ct_id},function(res){
                    if(res.code == 1){
                        form.val("formTest", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值                     
                            'data_version_name': res.data.data_version_name,
                            'username': res.data.username,                       
                            'subject': res.data.subject,                       
                            'grade': res.data.grade,                       
                            'class': res.data.class,                       
                            'title': res.data.title,                       
                            //'zf': res.data.zf,                       
                            //'pjf': res.data.pjf,                       
                            //'rank': res.data.pm != ''?res.data.pm.ranks+'/'+res.data.pm.rank_sum:'',                       
                        });
                        
                        //渲染审核小组成员
                        let getTpl = demo.innerHTML
                            ,view = document.getElementById('kpxzcc');
                            laytpl(getTpl).render(res.data, function(html){
                            view.innerHTML = html; 
                            $('#kpxzcc').find('span:first').addClass('kpxzcc-this');                            
                        }); 
                        
                        //默认点击最终认定
                        $('#tab-t').find('.layui-this').click();
                    }
                })
               
                
            }          
        });
    
        //下拉框初始化
        async function renderSelect(callback){   
            callback();
        }  


        //评分模块查看
        $(document).on('click','.module-see',function(){
            let data = $.parseJSON($(this).attr('data'));  
            let materials_date = data.materials_array; 
           // console.log(data);
            switch(data.module_id){
                case '4':
                    var title = '经验交流 - 查看';
                    var url = "{{route('rating.check.jyjl')}}?materials_date="+JSON.parse(materials_date)+'&user_id='+user_id;
                    break;
                case '5':
                    var title = '课题研究 - 查看';
                    var url = "{{route('rating.check.ktyj')}}?materials_date="+JSON.parse(materials_date)+'&user_id='+user_id;
                    break;
                case '6':
                    var title = '论文发表 - 查看';
                    var url = "{{route('rating.check.lwfb')}}?materials_date="+JSON.parse(materials_date)+'&user_id='+user_id;
                    break;
                case '7':
                    var title = '论著发表 - 查看';
                    var url = "{{route('rating.check.lzfb')}}?materials_date="+JSON.parse(materials_date)+'&user_id='+user_id;
                    break;
                case '19':
                    var title = '带教情况 - 查看';
                    var url = "{{route('rating.check.djqk')}}?materials_date="+JSON.parse(materials_date)+'&user_id='+user_id;
                    break;
                default:
                
            }

            layer.open({
                title :title,
                type: 2, 
                content: url ,
                area: ['1400px', '800px'],
                btn: [ '取消'],
                btnAlign: 'c',
                yes: function(index, layero){
                    layer.closeAll();
                }
                
            }); 
        })

        //获取最终认定
        function _getFinalScores(parm){
            getFinalScores(parm,function(res){
                if(res.code == 1){
                    if(res.data.table_data.length>0){
                        let tier = res.data.table_data[0].tier;
                        var cols = [];
                        cols.push({type: 'numbers', title: '序号'});
                        for (let i2 = 1;i2<=tier;i2++) { 
                            if(i2 == 1){
                                cols.push({field: 'title1',merge: 'title1', title: '一级指标'});
                            }else if(i2 == 2){
                                cols.push({field: 'title2',merge: 'title2', title: '二级指标'});
                            }else if(i2 == 3){
                                cols.push({field: 'title3',merge: 'title3', title: '三级指标'});
                            }else if(i2 == 4){
                                cols.push({field: 'title4',merge: 'title4', title: '四级指标'});
                            }                         
                        }
                        
                        delete cols[tier-1].merge; //最后一级指标不需要合并
                        cols.push({field: 'check_module_text', title: '参考材料', width:'30%',style:"height:auto",templet:'#titleTpl2'});
                        //cols.push({field: 'score', title: '单项分数', align: 'center',edit: 'text'});
                        cols.push({field: '', title: '评分', align: 'center',style:'height:auto;padding: 0px 15px',templet:'#titleTpl'});
                        //console.log(res.data.table_data);
                        table.render({
                            elem: '#tablelist'
                            ,limit: 300
                            ,data: res.data.table_data
                            ,css:'.layui-table-main{border-left: 1px #eee solid;border-right: 1px #eee solid;border-bottom:1px #eee solid}'
                            ,cols: [cols]
                            ,done: function(res, curr, count){
                                tableMerge.render(this);
                            }
                        });
                    }
                    form.val("formTest", {                                          
                            'zf': res.data.zf,                       
                            'pjf': res.data.pjf,                       
                            'rank': res.data.pm != ''?res.data.pm.ranks+'/'+res.data.pm.rank_sum:'',                       
                        });
                }
            })
        }

        //考核小组评分
        function _getCheckScores(parm){
            getCheckScores(parm,function(res){
                if(res.code == 1){
                    if(res.data.table_data.length>0){
                        let tier = res.data.table_data[0].tier;
                        var cols = [];
                        cols.push({type: 'numbers', title: '序号'});
                        for (let i2 = 1;i2<=tier;i2++) { 
                            if(i2 == 1){
                                cols.push({field: 'title1',merge: 'title1', title: '一级指标'});
                            }else if(i2 == 2){
                                cols.push({field: 'title2',merge: 'title2', title: '二级指标'});
                            }else if(i2 == 3){
                                cols.push({field: 'title3',merge: 'title3', title: '三级指标'});
                            }else if(i2 == 4){
                                cols.push({field: 'title4',merge: 'title4', title: '四级指标'});
                            }                         
                        }
                        
                        delete cols[tier-1].merge; //最后一级指标不需要合并
                        cols.push({field: 'check_module_text', title: '参考材料', width:'30%',style:"height:auto",templet:'#titleTpl2'});
                        //cols.push({field: 'score', title: '单项分数', align: 'center',edit: 'text'});
                        cols.push({field: '', title: '评分', align: 'center',style:'height:auto;padding: 0px 15px',templet:'#titleTpl'});
                        //console.log(res.data.table_data);
                        table.render({
                            elem: '#tablelist2'
                            ,limit: 300
                            ,data: res.data.table_data
                            ,css:'.layui-table-main{border-left: 1px #eee solid;border-right: 1px #eee solid;border-bottom:1px #eee solid}'
                            ,cols: [cols]
                            ,done: function(res, curr, count){
                                tableMerge.render(this);
                            }
                        });
                    }
                    form.val("formTest", {                                          
                            'zf': res.data.zf,                       
                            'pjf': res.data.pjf,                       
                            'rank': res.data.pm != ''?res.data.pm.ranks+'/'+res.data.pm.rank_sum:'',                       
                        });

                    $('#check-zs').text(res.data.zf != ''?res.data.zf:0);
                }
            })
        }

        //考核小组成员点击
        $(document).on('click','.kpcc',function(){
            $(this).addClass('kpxzcc-this').siblings().removeClass('kpxzcc-this');
            let p_user_id = $('#kpxzcc').find('.kpxzcc-this').attr('user-id'); 
            _getCheckScores({'id':id,scale_id:scale_id,user_id:user_id,ct_id:ct_id,p_user_id:p_user_id});
        })

        $('#fanhui').click(function(){
            parent.layer.closeAll();
        })
               
    });
</script>
<script id="demo" type="text/html">
    @{{#  layui.each(d.leader_array.all, function(k, v){ }}
        <span class="kpcc" user-id="@{{v.value}}" style="line-height: 38px;border: 1px solid #eee;padding: 10px;color:#0e90d2;cursor: pointer;" >@{{v.name}}</span> 
    @{{#  }); }} 
    @{{#  layui.each(d.members_array.all, function(k, v){ }}
        <span class="kpcc" user-id="@{{v.value}}" style="line-height: 38px;border: 1px solid #eee;padding: 10px;color:#0e90d2;cursor: pointer;" >@{{v.name}}</span> 
    @{{#  }); }} 
</script>
<script type="text/html" id="tips">  
    @{{#  layui.each(d, function(index, item){ }}
        <p>提示@{{++index}}：@{{- item}}</p>
    @{{#  }); }}
    <p>是否确认提交当前操作？</p>
</script>
<script type="text/html" id="titleTpl">   
    <input disabled data="@{{JSON.stringify(d)}}" type="text" max="@{{# if(d.single_score == 0.0){ }}1000@{{# }else{ }}@{{d.single_score}}@{{# } }}" min="0"  name="scores[]" value="@{{# if(d.pf_score_json != ''){ }}@{{d.pf_score_json.pj_scores}}@{{# }else{ }}@{{# } }}" autocomplete="off" required  lay-verify="required" lay-reqText="请填写分数" class="layui-input verify-score mark_score" onkeyup="value=value.replace(/[^\d.]/g,'').replace(/\.{2,}/g,'.').replace(/^(\-)*(\d+)\.(\d).*$/,'$1$2.$3')" style="text-align: center;">
    <input type="text" name="scores2[]" value="@{{# if(d.pf_score_json != ''){ }}@{{JSON.stringify(d.pf_score_json)}}@{{# }else{ }}@{{JSON.stringify(d.jc_score_json)}}@{{# } }}" style="display:none" >  
</script>
<script type="text/html" id="titleTpl2">  
    @{{# if(d.check_module_text != '无'){ }}
        @{{# if(d.module_info.length>0){ }}
            @{{#  layui.each(d.module_info, function(k, v){ }}
                <p>@{{v.name}}（@{{v.count}}条数据）<span class="module-see" data="@{{JSON.stringify(v)}}" style="float: right;color: #1e9fff;cursor: pointer;" >查看</span></p>
            @{{#  }); }}
        @{{# }else{ }}
            <p></p>
        @{{# } }}       
    @{{# }else{ }}
        <p></p>
    @{{# } }} 
</script>
@endpush

@section('content')
<style>
    .opt-panel{padding: 20px;}
    .panel-title h3{font-weight: 800;margin-bottom: 20px;}

    #add-form{padding: 20px 5px;}
    .opt-area{display: flex;flex-direction: row-reverse;padding: 10px 20px;margin-bottom: 20px;}
    .opt-area button{margin-left: 10px;}
    .layui-table td{border-left: 1px red solid;}
    #tips-view{margin: 30px;}
    #tips-view p{line-height: 38px;}
    .kpxzcc-this{background: #0e90d2;color: #fff !important;}
</style>

<div class="layui-row">
    <div class="layui-panel opt-panel">
        <div class="panel-title">
            <h3>学年考核 - 基本信息</h3>
        </div>
        <form class="layui-form" action="" lay-filter="formTest">
        <div class="layui-row" >
                <div class="layui-form-item" >
                    <div class="layui-inline" style="width: 30%;">
                        <label class="layui-form-label" style="width:130px">学年学期：</label>
                        <div class="layui-input-inline" style="width: 59%;">
                        <input disabled type="text" name="data_version_name" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline" style="width: 30%;">
                        <label class="layui-form-label" style="width:130px">教师姓名：</label>
                        <div class="layui-input-inline" style="width: 59%;">
                        <input disabled type="text" name="username" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline" style="width: 30%;">
                        <label class="layui-form-label" style="width:130px" >任教学科：</label>
                        <div class="layui-input-inline" style="width: 59%;">
                        <input disabled type="text" name="subject" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item" >
                    <div class="layui-inline" style="width: 30%;">
                        <label class="layui-form-label" style="width:130px">任教年级：</label>
                        <div class="layui-input-inline" style="width: 59%;">
                        <input disabled type="text" name="grade" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline" style="width: 30%;">
                        <label class="layui-form-label" style="width:130px">任班主任班级：</label>
                        <div class="layui-input-inline" style="width: 59%;">
                        <input disabled type="text" name="class" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline" style="width: 30%;">
                        <label class="layui-form-label" style="width:130px" >职称：</label>
                        <div class="layui-input-inline" style="width: 59%;">
                        <input disabled type="text" name="title" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item" >
                    <div class="layui-inline" style="width: 30%;">
                        <label class="layui-form-label" style="width:130px">总分：</label>
                        <div class="layui-input-inline" style="width: 59%;">
                        <input disabled type="text" name="zf" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline" style="width: 30%;">
                        <label class="layui-form-label" style="width:130px">平均分：</label>
                        <div class="layui-input-inline" style="width: 59%;">
                        <input disabled type="text" name="pjf" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline" style="width: 30%;">
                        <label class="layui-form-label" style="width:130px">排名：</label>
                        <div class="layui-input-inline" style="width: 59%;">
                        <input disabled type="text" name="rank" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>

            </div>
            
            
        </form>
    </div>   
</div>


  
<div class="layui-row" style="margin-top:10px" >
    <div class="layui-panel opt-panel">

        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <ul class="layui-tab-title" id="tab-t">
                <li class="layui-this" lay-id="1">最终认定</li>
                <li lay-id="2">考核小组</li>
            </ul>
            <div class="layui-tab-content">

                <!--考核小组成员-->
                <div class="khxzcc-div" style="display:none;" >
                    <form class="layui-form" action="" >
                        <div class="layuik-form-item ">
                            <div class="layuik-inline">
                                <label class="layuik-form-label">考核小组成员：</label>
                                <div class="layuik-input-inline" style="width: 70%;">
                                    <div id="kpxzcc"></div>
                                </div>
                                <div class="layuik-input-inline" style="width: 20%;text-align: center;line-height: 38px;">
                                    个人考核总分：<span id="check-zs" style="font-size: 18px;font-weight: bold;" ></span> 分
                                </div>
                            </div>
                        </div>
                    </form>
                </div>

                <div class="layui-tab-item layui-show">
                    <div class="layui-row">    
                        <div  class="layui-row">                                                         
                            <table class="layui-table" id="tablelist" lay-filter="tablelist" ></table>            
                        </div>  
                    </div>
                </div>

                <div class="layui-tab-item">
                    <div  class="layui-row">                                                         
                        <table class="layui-table" id="tablelist2" lay-filter="tablelist2" ></table>            
                    </div>
                </div>

            </div>
        </div>

        <!-- <div class="layui-card">
           
                
          
        </div> -->

        
        <div class="layui-row">
                <div class="opt-area">
                    <a _href="" ><button class="layui-btn layui-btn-primary" id="fanhui" type="button">返回</button></a>
                    <!-- <button class="pear-btn pear-btn-primary" type="button" id="formDemo" lay-filter="formDemo">提交</button> -->
                </div> 
            </div>
    </div>
</div>

<div id="tips-view" style="display:none" >

</div>
@endsection